

#include "CxType.h"
#include "CxRevThread.h"




using namespace MSG_SIGN;

//Init  member  variable
CxRevThread::CxRevThread(_Serial *port):m_mode(mode_serial),m_protohandle(new CxProtocolHandle_1),
										m_serialport(port),m_tcpclient(NULL),
										m_transbuffer(1024),b_spin(true)
{
}

CxRevThread::CxRevThread(_TcpClient *port):m_mode(mode_tcp),m_protohandle(new CxProtocolHandle_1),
										m_serialport(NULL),m_tcpclient(port),
										m_transbuffer(1024),b_spin(true)
{
}


CxRevThread::~CxRevThread()
{

}



void		CxRevThread::run()
{
	//Main handle
	while(b_spin)
	{
		boost::this_thread::sleep(boost::posix_time::milliseconds(50));

		switch(m_mode)
		{
		case mode_serial:

			m_protohandle->HandlePort(*m_serialport,m_transbuffer);

			break;
		case mode_tcp:

			m_protohandle->HandlePort(*m_tcpclient,m_transbuffer);

			break;
		}
		boost::this_thread::interruption_point();
	}
}
